import { ITodo } from '@/typeings';

export interface IUseLocalStorage {
    GetLocalList : () => ITodo[];
    SetLocalList : (todoList : ITodo[]) => void;
}

function useLocalStorage () {
    // '[]' 字符串数组
    function GetLocalList () : ITodo[] {
        return JSON.parse( localStorage.getItem('todoList') || '[]' )
    }

    function SetLocalList ( todoList : ITodo[] ) : void {
        localStorage.setItem('todoList' , JSON.stringify(todoList) )
    }

    return {
        GetLocalList, 
        SetLocalList
    }
}

export {
    useLocalStorage
}